package com.sos.core.cards
{
	import com.sos.utils.ClassUtils;

	public class CardSet
	{
		
		// -------------------------------------------------------------------------------
		// CONSTANTS
		// -------------------------------------------------------------------------------	
		
		public static const BASIC_SET:CardSet		= new CardSet(1, "Basic Set");
		
		// -------------------------------------------------------------------------------
		// STATIC
		// -------------------------------------------------------------------------------
		
		private static var _initialized:Boolean = false;
		private static var _list:Vector.<CardSet>;
		
		// Fake static constructor
		{
			// Fill the internal list
			_list = new Vector.<CardSet>();
			_list.push(CardSet.BASIC_SET);
			// Init!
			_initialized = true;
		}
		
		// -------------------------------------------------------------------------------
		// FIELDS
		// -------------------------------------------------------------------------------
		
		private var _id:uint;
		private var _name:String;
		
		// -------------------------------------------------------------------------------
		// CONSTRUCTORS
		// -------------------------------------------------------------------------------
		
		public function CardSet(id:uint, name:String)
		{
			// Safe unique instance lock
			if (_initialized) throw new Error("CardSet enum already created!");
			// Init
			_id    = id;
			_name  = name;
		}
		
		// -------------------------------------------------------------------------------
		// PROPERTIES
		// -------------------------------------------------------------------------------		
		
		public function get id():uint
		{
			return _id;
		}
		
		public function get name():String
		{
			return _name;
		}
		
		// -------------------------------------------------------------------------------
		// PUBLIC METHODS
		// -------------------------------------------------------------------------------
		
		public function toString():String
		{
			return ClassUtils.getName(this) + "." + _name;
		}
		
		// -------------------------------------------------------------------------------
		// STATIC METHODS
		// -------------------------------------------------------------------------------
		
		/**
		 * Returns the list of the names of 
		 * @return 
		 */
		public static function names():Array
		{
			var list:Array  = new Array;
			// Loop over values list
			for (var i:int=0; i<_list.length; i++)
			{
				list.push(_list[i].name);
			}
			return list;
		}
		
		/**
		 * 
		 * @return 
		 */
		public static function list():Array
		{
			var list:Array = new Array;
			// Loop over values list
			for (var i:int=0; i<_list.length; i++)
			{
				list.push(_list[i]);
			}
			return list;
		}
		
		/**
		 * Search a CardSet by given id 
		 * @param id Id of the card type to find
		 * @return PlayerRole constant for the given id, null if no CardSet
		 * for the given id has been found
		 */
		public static function getById(id:uint):CardSet
		{
			// Search the value into the list
			for (var i:int=0; i<_list.length; i++)
			{
				if (_list[i].id == id) return _list[i];
			}
			return null;
		}
		
		/**
		 * Search a CardSet by given name 
		 * @param name Name of the player role to find
		 * @return CardSet constant for the given id, null if no CardSet
		 * for the given id has been found
		 */
		public static function getByName(name:String):CardSet
		{
			// Search the value into the list
			for (var i:int=0; i<_list.length; i++)
			{
				if (_list[i].name == name) return _list[i];
			}
			return null;
		}
	
	}
}